package com.codedancer.campus.client.api.contactAdmin;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.codedancer.campus.client.api.contactAdmin.ro.ContactAdminChatMessagePageSearchRo;
import com.codedancer.campus.client.service.IContactAdminService;
import com.codedancer.campus.client.service.bo.contactAdmin.ContactAdminChatMessagePageSearchBo;
import com.codedancer.campus.client.service.vo.contactAdmin.ContactAdminChatRoomVo;
import com.codedancer.campus.client.service.vo.contactAdmin.ContactAdminChatMessagePageVo;
import com.codedancer.campus.common.core.BaseApi;
import com.codedancer.campus.common.response.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/contact-admin")
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE,
    RequestMethod.PUT}, maxAge = 3600)
@Api(value = "联系管理员Api", description = "联系管理员Api", tags = "联系管理员Api")
public class ContactAdminApi extends BaseApi {

    @Autowired
    private IContactAdminService contactAdminService;

    @GetMapping("/get-chatRoom/{adminUuid}")
    @ApiOperation("获取和某个管理员的聊天室")
    public ApiResponse<ContactAdminChatRoomVo> getChatRoom(@PathVariable(value = "adminUuid", required = true) @ApiParam(value = "管理员uuid", required = true) String adminUuid) {
        return success(contactAdminService.getChatRoom(currentLoginUuid(), adminUuid));
    }

    @GetMapping("/page/history/{chatRoomUuid}")
    @ApiOperation("获取聊天记录")
    public ApiResponse<IPage<ContactAdminChatMessagePageVo>> pageHistory(
        @PathVariable(value = "chatRoomUuid", required = true) @ApiParam(value = "聊天室uuid", required = true) String chatRoomUuid,
        @ApiParam(value = "联系管理员聊天信息分页查询Ro", required = false) ContactAdminChatMessagePageSearchRo contactAdminChatMessagePageSearchRo) {
        ContactAdminChatMessagePageSearchBo contactAdminChatMessagePageSearchBo = BeanUtil.copyProperties(contactAdminChatMessagePageSearchRo, ContactAdminChatMessagePageSearchBo.class);
        contactAdminChatMessagePageSearchBo.setChatRoomUuid(chatRoomUuid);
        return success(contactAdminService.pageHistory(contactAdminChatMessagePageSearchBo));
    }
}
